package com.hnevc.recyclerviewdemo;

import android.content.res.TypedArray;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

public class MainActivity extends AppCompatActivity {

    //声明变量，用来指向布局文件中的R.id.id_rv_views控件
    RecyclerView mRecyclerView;

    //获取资源文件中的数据
    String[] datas;
    TypedArray images;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        datas = getResources().getStringArray(R.array.datas);
        images = getResources().obtainTypedArray(R.array.pics);

        mRecyclerView = (RecyclerView) findViewById(R.id.id_rv_views);

        //定义LinearLayoutManager:布局显示方式

        //LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);

        //GridLayoutManager layoutManager = new GridLayoutManager(this,3);
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);




        //创建Adatper
        MyAdapter adapter = new MyAdapter(datas,images,this);
        //绑定显示数据
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setAdapter(adapter);

    }
}
